<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">

    <link rel="stylesheet" href="/gupiao/css/weui.css">
    <link rel="stylesheet" href="/gupiao/css/jquery-weui.css">
    <link rel="stylesheet" href="/gupiao/css/style.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_689900_raxzqh2p8ixm9529.css">

    <style>

    </style>
</head>
<body class="back1">

    <div class="index-top-fix">
        <a href="{:url('gupiao.lists/shareList',['type'=>'share'])}" class="iconfont icon-left- left"></a>
        <p class="title">分享详情</p>
    </div>

    <div class="mt50"></div>

    <div style="background: #fff;">
        <div class="article">

            <div class="article-hd">

                <h3 style="text-align:center;font-size:18px;" id="artTitle"></h3>

                <span style="margin-left: 5px;">作者：</span>
                <span id="artAuthor"></span>

                <span style="float:right;margin-right:2px;" id="artTime"></span><br/>

                <p style="text-align:right;margin-right: 2px;">浏览量：<span id="artNum"></span> 次</p>
            </div>

            <div class="article-bd" id="artCont"></div>

        </div>
    </div>

    <div class="article-box">
        <h2>精品留言</h2>
        <div id="commentLI"></div>
    </div>

    <div class="weui-loadmore" id="loadmore2">
        <span class="weui-loadmore__tips">加载更多</span>
    </div>

    <div class="mb70"></div>

    <div class="comment-pos">

        {if $admin == 1}
            <form action="" method="post" id="add1" style="display:none;">
                <input type="hidden" id="id" name="id" value="{$id}">
                <input type="hidden" id="uid" name="uid" >
                <input type="text" name="content">
                <a href="javascript:;"  onclick="login2()">回复</a>
            </form>
        {else if $admin == 0}
            <form action="" method="post" id="add">
                <input type="hidden" id="id" name="id" value="{$id}">
                <input type="text" name="content">
                <a href="javascript:;"  onclick="login()">评论</a>
            </form>
        {/if}

    </div>

    <script src="/gupiao/js/jquery.min.js"></script>
    <script src="/gupiao/js/jquery-weui.min.js"></script>
</body>
</html>


<script>
    // 刚进入界面  进行数据初始化加载
    $(function() {

        // 获取文章id
        var id = document.getElementById("id").value;

        // 获取文章详情
        $.ajax({
            type: "GET",
            url: "{:url('gupiao.Article/info')}",
            data: {id:id},
            dataType: 'json',
            success: function (res) {
                // alert(res.code);
                if (res.code == 200) {
                    $("#artTitle").text(res.data.title);
                    $("#artTime").text(res.data.create_time);
                    $("#artCont").html(res.data.content);
                    $("#artNum").html(res.data.num);
                    $("#artAuthor").html(res.data.author);
                }
            }
        });

        // 获取第一页评论
        talklist(0);

        // 获取评论列表
        function talklist(_page){
            _page++;

            // 评论列表是要加下拉刷新的
            $.ajax({
                type: "GET",
                url: "{:url('gupiao.article/talkList')}",
                data: {id:id,page:_page},
                dataType: 'json',
                success: function (res) {
                    var  html ='';
                    if (res.code == 200) {
                        for(var i=0;i<res.data.length;i++){
                            var data = res.data[i];
                            if(res.is_manager == "0"){

                                // 用户可看
                                html += 
                                    "   <div class=\"comment-li\">\n" +
                                    "       <img src="+data.avatar+" width=\"50\">\n" +
                                    "       <div class=\"com\">\n" +
                                    "           <div class=\"name\">\n" +
                                    "               <p class=\"p1\">"+data.name+"</p>\n" +
                                    "           </div>\n" +
                                    "           <div>"+data.content+"</div>\n" +
                                    "           <div>"+data.time+"</div>\n" +
                                    "       </div>\n" +
                                    "   </div>";

                            } else if(res.is_manager == "1"){

                                // 讲师可看
                                html += 
                                    "   <div class=\"comment-li\">\n" +
                                    "       <img src="+data.avatar+" width=\"50\">\n" +
                                    "       <div class=\"com\">\n" +
                                    "           <div class=\"name\">\n" +
                                    "               <p class=\"p1\">"+data.name+"</p>\n" +
                                    "               <a class=\"hf\" href=\"javascript:;\" onclick='contF("+data.id+")'>回复</a>\n" +
                                    "           </div>\n" +
                                    "           <div>"+data.content+"</div>\n" +
                                    "           <div>"+data.time+"</div>\n" +
                                    "       </div>\n" +
                                    "   </div>";
                            }
                        }

                        // 数据展示方式
                        if(_page == 1){
                            $("#commentLI").html(html);    
                        }else{
                            $("#commentLI").append(html);
                        }
                        
                        // locading  这个时候关闭
                        if(res.data.length < 15){
                            $("#loadmore2").hide();
                        }
                        
                        $("#loadmore2").click(function(){
                            talklist(_page);  
                        });

                    }
                }
            })
        }
        
    });


</script>

<!--提交用户评论-->
<script>
    // 用户留言
    function login() {
        $.ajax({
            type: "POST",                       //方法类型
            dataType: "json",                   //预期服务器返回的数据类型
            url: "{:url('gupiao.article/talk')}" ,        //url
            data: $('#add').serialize(),
            success: function (res) {
                if (res.code == 200) {
                    alert('留言成功！');
                    window.location.reload();
                };
            },
            error : function() {
                alert("异常！");
            }
        });
    }

</script>


<!--管理员回复留言-->
<script>

    // 参数处理
    function contF(id) {
        $("#uid").val(id);
        $("#add1").show();
    }

    // 管理员回复留言
    function login2() {

        $.ajax({
            type: "POST",                                   // 方法类型
            dataType: "json",                               // 预期服务器返回的数据类型
            url: "{:url('gupiao.article/replyTalk')}" ,     // url
            data: $('#add1').serialize(),
            success: function (res) {
                if (res.code == 200) {
                    alert('回复留言成功！');
                    window.location.reload();
                };
            },
            error : function() {
                alert("异常！");
            }
        });
    }
</script>

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    //
    wx.config({
        debug: false,
        appId: '{$jsconfig.appId}',
        timestamp: '{$jsconfig.timestamp}',
        nonceStr: '{$jsconfig.noncestr}',
        signature: '{$jsconfig.signature}',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onRecordEnd',
            'playVoice',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });
    wx.isInit = false;

    wx.ready(function () {

        //分享给朋友
        wx.onMenuShareAppMessage({
            title: "邀请您阅读最专业靠谱的股票行情分析文章",            // 分享标题 此处$title可在控制器端传递也可在页面传递 页面传递讲解在下面哦
            desc: "一哥股票点评，提供专业，靠谱的股票点评",             // 分享描述
            link: "{$web_url}",  // 分享链接
            imgUrl: "{$share_icon}",   // 分享图标
            type: '', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                alert('分享成功');
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                alert('取消分享');
            }
        });
        //分享到朋友圈
        wx.onMenuShareTimeline({
            title: "邀请您阅读最专业靠谱的股票行情分析文章",               // 分享标题
            desc: "一哥股票点评，提供专业，靠谱的股票点评",                // 分享描述
            link: "{$web_url}",      // 分享链接
            imgUrl: "{$share_icon}",         // 分享图标
            success: function () {
                // 用户确认分享后执行的回调函数
                alert('分享成功');
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                alert('取消分享');
            }
        });
    });

    wx.error(function (res) {
        alert(res.errMsg);
    });


</script>

